﻿Option Explicit On
Option Strict On

Imports System
Imports System.Globalization
Namespace EvenHand

    Public NotInheritable Class KeyEventHand

#Region "InputLanguage Function                     "
        Public Overloads Shared Function InputLanguage(ByVal value As String) As String
            Dim tmp As String = ""
            Select Case value
                Case "US"
                    tmp = "en"
                Case "Thai Kedmanee"
                    tmp = "th"
            End Select
            Return tmp
        End Function

        Public Overloads Shared Function OutputLanguage(ByVal value As String) As String
            Dim tmp As String = ""
            Select Case value
                Case "US"
                    tmp = "US"
                Case "en"
                    tmp = "US"
                Case "Thai Kedmanee"
                    tmp = "TH"
            End Select
            Return tmp
        End Function
#End Region

        Public Shared GotForeColor As System.Drawing.Color = System.Drawing.Color.Black
        Public Shared GotBackColor As System.Drawing.Color = System.Drawing.Color.GreenYellow

        Public Shared LostForeColor As System.Drawing.Color = System.Drawing.SystemColors.ControlText
        Public Shared LostBackColor As System.Drawing.Color = System.Drawing.Color.White
        Public Shared Sub TextBox_GotFocus(ByVal sender As System.Object, ByVal e As System.EventArgs)
            Dim TextBox As System.Windows.Forms.TextBox = CType(sender, System.Windows.Forms.TextBox)
            TextBox.ForeColor = GotForeColor
            TextBox.BackColor = GotBackColor
            TextBox.Focus()
            TextBox.SelectAll()
        End Sub

        Public Shared Sub TextBox_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs)
            Dim TextBox As System.Windows.Forms.TextBox = CType(sender, System.Windows.Forms.TextBox)
            TextBox.ForeColor = LostForeColor
            TextBox.BackColor = LostBackColor
        End Sub

        Public Shared Sub ComboBox_GotFocus(ByVal sender As System.Object, ByVal e As System.EventArgs)
            Dim ComboBox As System.Windows.Forms.ComboBox = CType(sender, System.Windows.Forms.ComboBox)
            ComboBox.ForeColor = GotForeColor
            ComboBox.BackColor = GotBackColor
        End Sub

        Public Shared Sub ComboBox_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs)
            Dim ComboBox As System.Windows.Forms.ComboBox = CType(sender, System.Windows.Forms.ComboBox)
            ComboBox.ForeColor = LostForeColor
            ComboBox.BackColor = LostBackColor
        End Sub

        Public Shared Sub NumOnly_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
            Dim TextBoxs As System.Windows.Forms.TextBox = CType(sender, System.Windows.Forms.TextBox)
            If TextBoxs.Text.Length < 255 Then
                If Not Char.IsDigit(e.KeyChar) And Not Char.IsControl(e.KeyChar) And Not e.KeyChar = "." Then
                    e.Handled = True
                Else
                    If e.KeyChar = "." Then
                        e.Handled = True
                    End If
                End If
            Else
                e.Handled = True
            End If
        End Sub

        Public Shared Sub Phone_Keypress(ByVal Sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
            Dim TextBoxs As System.Windows.Forms.TextBox = CType(Sender, System.Windows.Forms.TextBox)
            If TextBoxs.Text.Length < 255 Then
                If Not Char.IsDigit(e.KeyChar) And Not Char.IsControl(e.KeyChar) And Not e.KeyChar = "-" And Not e.KeyChar = "#" And Not e.KeyChar = "," Then
                    e.Handled = True
                Else
                    'If e.KeyChar = "-" And TextBoxs.Text.IndexOf("-") <> -1 Then
                    'e.Handled = True
                    ' End If

                    'If e.KeyChar = "#" And TextBoxs.Text.IndexOf("#") <> -1 Then
                    'e.Handled = True
                    ' End If
                End If
            Else
                e.Handled = True
            End If
        End Sub

        Public Shared Sub ComboBox_Keypress(ByVal Sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
            e.Handled = True
        End Sub

        Public Shared Sub NumReal_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
            Dim TextBoxs As System.Windows.Forms.TextBox = CType(sender, System.Windows.Forms.TextBox)
            If TextBoxs.Text.Length < 255 Then
                If Not Char.IsDigit(e.KeyChar) And Not Char.IsControl(e.KeyChar) And Not e.KeyChar = "." Then
                    e.Handled = True
                Else
                    If e.KeyChar = "." And TextBoxs.Text.IndexOf(".") <> -1 Then
                        e.Handled = True
                    End If
                End If
            Else
                e.Handled = True
            End If
        End Sub

        Public Shared Function GetMSG(ByVal Action As String) As String
            Dim MSG As String = ""
            If Action = "Add" Then
                MSG = "You Want Create New Data ?"
            ElseIf Action = "Edit" Then
                MSG = "You Want Edit Data ?"
            End If
            Return MSG
        End Function
    End Class
End Namespace

Module mdUseall

    '******* เก็บค่าวันที่จากเครื่อง Server***********
    Public TMP_DATE_AT_SERVER As DateTime
    '*****************************************

End Module
